<!--
 * @Author: your name
 * @Date: 2020-12-08 14:46:38
 * @LastEditTime: 2021-03-22 09:30:27
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\warranty\warrantyStatistics\examine.vue
-->
<template>
    <div class="examine-main-box">
        <el-dialog
        :title="$t('warrantyStatistics.comparison')"
        :visible="visibleAdd2"
        width="50%"
        @close="()=>{$store.commit('setVisibleAdd2',false)}"
        :close-on-click-modal='false'
        >
        <div class="content-box-text">
            <div class="row-box header-box">
                <div class="row-box-sub">{{$t('warrantyStatistics.tableName')}}</div>
                <div class="row-box-sub">{{$t('warrantyStatistics.qdata')}}</div>
                <div class="row-box-sub">{{$t('warrantyStatistics.sdata')}}</div>
            </div>
            <div class="row-box" v-for='(item,key,index) in dataList.systemData' :key='index' v-if="key !='installerSid'&&key !='installerId'" :class="returnColorName(key)">
                <!-- &&key !='accessTime'&&key !='strInstallTime' -->
                <div class="row-box-sub">{{returnText(key)}}</div>
                <div class="row-box-sub">{{dataList.qualityData[key] || ' - '}}</div>
                <div class="row-box-sub">{{item || ' - '}}</div>
            </div>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="()=>{$store.commit('setVisibleAdd2',false)}" style="margin-right:10px;">{{$t('cancel')}}</el-button>
            <el-button type="primary" @click="showRejectModal" style="margin-right:10px;">{{$t('warranty.reject')}}</el-button>
            <el-popconfirm
            :title="$t('device-confirm-verify')"
            @confirm='qualityNewCheckAndSendInvoice()'
            :confirm-button-text="$t('sure')"
            :cancel-button-text="$t('cancel')"
            >   
                <el-button type="primary" slot="reference"  style="margin-right:10px;">{{$t('warranty.audit.send')}}</el-button>
            </el-popconfirm>
            <el-popconfirm
            :title="$t('warrantyStatistics.invoice')"
            @confirm='qualityCheckQuality()'
            :confirm-button-text="$t('sure')"
            :cancel-button-text="$t('cancel')"
            >   
                <el-button type="primary" slot="reference">{{$t('sure')}}</el-button>
            </el-popconfirm>
        </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        editRow:{
            type:Object,
            default:()=>{return {}}
        },
        inverterType:{
            type:Array,
            default:()=>{return []}
        },
    },
    data() {
        return {
            dataList:{}
        };
    },
    computed: {
        visibleAdd2(){
            return this.$store.state.sysStore.visibleAdd2
        },
    },
    watch: {
        visibleAdd2:{
            handler(nv,ov){
                if(nv){
                    this.qualityCompareQualityInfomation()
                }
            }
            
        }
    },
    created() {

    },
    mounted() {
        
    },
    methods: {
        showRejectModal(){
            this.$store.commit('setRightVisible',true)
            this.$store.commit('setrejectWarrantyId',this.editRow.sid)
        },
        async qualityNewCheckAndSendInvoice(){
            let deviceTypeName=this.editRow.deviceType == 16?this.editRow.deviceTypeName:this.comm.returnCode(this.inverterType,this.editRow.deviceType,'inverterType','inverterTypeName')
            let res = await this.API.qualityNewCheckAndSendInvoice({
                id:this.editRow.sid,
                inverterSn:this.editRow.inverterSn,
                inverterType:deviceTypeName,
            })
            if(res.success){
                this.comm.showMsg(true)
                this.$store.commit('setVisibleAdd2',false)
                this.$emit('uploadData',true)
            }else{
                this.comm.showMsg(false)
            }
        },
        async qualityCheckQuality(){
            let deviceTypeName=this.editRow.deviceType == 16?this.editRow.deviceTypeName:this.comm.returnCode(this.inverterType,this.editRow.deviceType,'inverterType','inverterTypeName')
            let res = await this.API.qualityCheckQuality({
                id:this.editRow.sid,
                inverterSn:this.editRow.inverterSn,
                inverterType:deviceTypeName,
            })
            if(res.success){
                this.comm.showMsg(true)
                this.$store.commit('setVisibleAdd2',false)
                this.$emit('uploadData',true)
            }else{
                this.comm.showMsg(false)
            }
        },
        returnColorName(key){
            let letf = this.dataList.qualityData[key]
            let rigth = this.dataList.systemData[key]
            let name = ''
            if(this.isNull(letf) == this.isNull(rigth)){
                name = ''
            }
            if(this.isNull(letf) != this.isNull(rigth)){
                if(letf && (this.isNull(rigth))){
                    name = 'green'
                }else{
                    name = 'red'
                }
            }
            return name
        },
        isNull(val){
            if(val){
                return val
            }else{
                return '-'
            }
        },
        returnText(key){
            var obj={
                address: this.$t('address'),
                deviceType: this.$t('devWifi.deviceType'),
                email: this.$t('warrantyStatistics.email'),
    //			installerId: getText('#SinstallerName'),
    //			installerIds: getText('#SinverterSn'),
                installer: this.$t('warrantyStatistics.installerName'),
                inverterSn: this.$t('warrantyStatistics.inverterSn'),
                nation: this.$t('warrantyStatistics.nation'),
                phone: this.$t('warrantyStatistics.phone'),
                postCode: this.$t('warrantyStatistics.postCode'),
                userName: this.$t('warrantyStatistics.userName'),
                batterySN: this.$t('warrantyStatistics.batterySN'),
                model: this.$t('devWifi.deviceType'),
                accessTime: this.$t('warranty.Approval.Installation.Time'),
            }
            return obj[key]
        },
        async qualityCompareQualityInfomation(){
            let res = await this.API.qualityCompareQualityInfomation({
                id: this.editRow.sid,
                inverterSn: this.editRow.inverterSn,
                userId: this.editRow.userSid || ''
            })
            this.dataList = res.object||{}
            if(this.dataList){
                    this.dataList.qualityData.accessTime = this.dataList.qualityData.strInstallTime
            }
        }
    },
};
</script>

<style  lang="less" scoped>
.examine-main-box{
    .content-box-text{
        .row-box{
            display: flex;
            padding: 10px 0px;
        }
        .row-box-sub{
            flex: 1;
            word-break: break-all;
            text-align: center;
        }
        .header-box{
            background-color: #aaa !important;
        }
        .green{
            color: #008000;
        }
        .red{
            color: red;
        }
        .row-box:nth-child(2n+1){
            background-color: rgba(204, 204, 204, 0.26);
        }
    }
}
</style>
